<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div {
            margin: 200px;
        }

        span {
            display: inline-block;
            width: 40px;
            height: 40px;
            background-color: #333;
            font-size: 20px;
            color: #fff;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>
<body>
<div>
    <span class="hour">1</span>
    <span class="minute">2</span>
    <span class="second">3</span>
</div>
<script>
    var hour = document.querySelector('.hour');
    var minute = document.querySelector('.minute');
    var second = document.querySelector('.second');
    var inputTime = +new Date('2020-6-6 21:37'); // 返回的是用户输入时间总的毫秒数
    countTime();//先调用一次这个函数,避免刷新的时候空白
    setInterval(countTime,1000);
    function countTime() {
        var nowTime = +new Date();// 返回的是当前时间总的毫秒数
        console.log(nowTime);
        var times = (inputTime - nowTime) / 1000;//times 剩余时间总的毫秒数
        var h = parseInt(times / 60 / 60 % 24);//时
        h = h < 10 ? '0' + h : h;
        var m = parseInt(times / 60 / 60 % 60);//分
        m = m < 10 ? '0' + m : m;
        var s = parseInt(times % 60);//秒
        s = s < 10 ? '0' + s : s;
        hour.innerHTML = h;
        minute.innerHTML = m;
        second.innerHTML = s;
    }


</script>
</body>
</html>